import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:image_gallery_saver_plus/image_gallery_saver_plus.dart';
import 'package:lcapp/basic/user_info.dart';
import 'package:lcapp/data/lc_video_data_entity.dart';
import 'package:lcapp/data/xian_huo_data_entity.dart';
import 'package:lcapp/data/zixun_data_entity.dart';
import 'package:lcapp/model/share/custom_share.dart';
import 'package:lcapp/model/toast/toast.dart';
import 'package:lcapp/tools/date_util.dart';
import 'package:lcapp/tools/string_tool.dart';
import 'package:lcapp/widget/asr_cache_image.dart';
import 'package:path_provider/path_provider.dart';


class HomeSharepage extends StatefulWidget {
  final String? title;
  final String desc;
  final String webURL;
  final String? shareUrl;
  final Map<String,dynamic>? map;
  final LcVideoDataEntity? videoDataEntity;
  final ZixunDataEntity? zixunDataEntity;
  final XianHuoDataEntity? xianHuoDataEntity;
  final int? shareType; //1web 2图片
  final int? contentType; //0 咨询 1 视频 2 现货 3 邀请好友 4 邀请二维码
  final Function? clickFun;
  final bool? isJuBao;
  final String? imgUrl;
  final double? aspectRadio;
  const HomeSharepage({Key? key, this.title, this.desc="粮食生意不好做，看不透市场，就来粮策！为您的粮食生意保驾护航！", this.webURL="https://h.liangce.cc/#/", this.map, this.videoDataEntity, this.zixunDataEntity, this.xianHuoDataEntity, this.shareType=1, this.contentType, this.clickFun, this.isJuBao=false, this.shareUrl, this.imgUrl, this.aspectRadio}) : super(key: key);

  @override
  _HomeSharepageState createState() => _HomeSharepageState();
}

class _HomeSharepageState extends State<HomeSharepage> {

  String? webUrl;
  String title='粮策-买卖存粮有策略';
  GlobalKey _rootWidgetKey = GlobalKey();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    webUrl = widget.webURL;
    if(!widget.webURL.contains('lcID')){
      webUrl = webUrl! + '?lcID=${userInfo.id}';
    }
    if(widget.shareUrl!=null){
      webUrl = widget.shareUrl! + '&title=$title&desc=${widget.desc}';
    }
    title = (userInfo.addressRegin??'')+(userInfo.name??'')+'邀请您注册';
    if(widget.title!=null){
      title = widget.title!;
    }

    print('title========' + title);
    print('weburl========' + webUrl!);
    print('desc========' + widget.desc);

  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.transparent,
        borderRadius: BorderRadius.circular(20.w)
      ),
      child: Column(
        children: [
          Container(
            color: Colors.transparent,
            height: widget.contentType==4?ScreenUtil().statusBarHeight:ScreenUtil().statusBarHeight+30.w,
          ),
          Expanded(child: GestureDetector(
            onTap: (){
              SmartDialog.dismiss();
            },
            child: Container(
              alignment: Alignment.bottomCenter,
              margin: EdgeInsets.only(bottom: 30.w,left: 30.w,right: 30.w),
              padding: EdgeInsets.only(bottom: 10.w),
              decoration: BoxDecoration(
                color: Colors.transparent,
                borderRadius: BorderRadius.circular(10.w),
              ),
              child: SingleChildScrollView(
                child: RepaintBoundary(
                  key: _rootWidgetKey,
                  child: Container(
                      decoration: BoxDecoration(
                          color:Colors.transparent,
                          borderRadius: BorderRadius.circular(10.w)
                      ),
                      child: widget.shareType!=2?Container():
                      widget.contentType==0?
                      zxWidget():
                      widget.contentType==1?
                      videoWidget():
                      widget.contentType==2?
                      xianhuoWidget():
                      widget.contentType==4?
                      yqWidget():Container()
                  ),
                ),
              ),
            ),
          )),
          Container(
            padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20.w),
                color: Colors.white,
            ),
            child: Column(
              children: [
                Container(
                  padding:EdgeInsets.only(left: 30.w,right: 30.w,top: 30.w),
                  alignment: Alignment.centerLeft,
                  // child: Text('分享',style: TextStyle(
                  //   color: Colors.black,
                  //   fontSize: 32.sp,
                  //   fontWeight: FontWeight.w500
                  // ),),
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      GestureDetector(
                        onTap: ()async{
                          SmartDialog.dismiss();
                          if(widget.shareType == 2){
                            String savePath = await _screenshotImg();
                            // final dir = await getTemporaryDirectory();
                            // String path = dir.path;
                            // String fileName =
                            //     DateTime.now().microsecondsSinceEpoch.toString() + '.jpg';
                            // savePath = await _screenshotController.captureAndSave(path,
                            //     fileName: fileName,
                            //     pixelRatio: window.devicePixelRatio ?? 2);
                            // CustomShare().WXPYQsahreImg(title, widget.desc, savePath,map: widget.map);
                          }else{
                            // CustomShare().WXPYQsahreWeb(title, widget.desc, webUrl,map: widget.map,imgUrl: widget.imgUrl);
                          }
                        },
                        child: Container(
                          // width: 135.w,
                          // margin: EdgeInsets.only(right: 30.w),
                          child: Column(
                            children: [
                              Image.asset("assets/share/share_pyq.png",width: 90.w,),
                              SizedBox(height: 10.w,),
                              Text('朋友圈',style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 28.sp
                              ),)
                            ],
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: ()async{
                          SmartDialog.dismiss();
                          if(widget.shareType == 2){
                            String savePath;
                            final dir = await getTemporaryDirectory();
                            String path = dir.path;
                            String fileName =
                                DateTime.now().microsecondsSinceEpoch.toString() + '.jpg';
                            savePath = await _screenshotImg();
                            // CustomShare().WXsahreImg(title, widget.desc, savePath,map: widget.map);
                          }else{
                            // CustomShare().WXsahreWeb(title, widget.desc, webUrl,map: widget.map,imgUrl: widget.imgUrl);
                          }
                        },
                        child: Container(
                          // width: 135.w,
                          // margin: EdgeInsets.only(right: 40.w),
                          child: Column(
                            children: [
                              Image.asset("assets/share/share_wx.png",width: 90.w,),
                              SizedBox(height: 10.w,),
                              Text('微信好友',style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 28.sp
                              ),)
                            ],
                          ),
                        ),
                      ),
                      GestureDetector(
                        onTap: ()async{
                          SmartDialog.dismiss();
                          if(widget.shareType == 2){
                            String savePath;
                            final dir = await getTemporaryDirectory();
                            String path = dir.path;
                            String fileName =
                                DateTime.now().microsecondsSinceEpoch.toString() + '.jpg';
                            savePath = await _screenshotImg();
                            // CustomShare().QQsahreImg(title, widget.desc, savePath,map: widget.map);
                          }else{
                            // CustomShare().QQsahreWeb(title, widget.desc, webUrl,map: widget.map,imgurl: widget.imgUrl);
                          }
                        },
                        child: Container(
                          // width: 135.w,
                          // margin: EdgeInsets.only(right: 40.w),
                          child: Column(
                            children: [
                              Image.asset("assets/share/share_qq.png",width: 90.w,),
                              SizedBox(height: 10.w,),
                              Text('QQ分享',style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 28.sp
                              ),)
                            ],
                          ),
                        ),
                      ),
                      Visibility(child: GestureDetector(
                        onTap: ()async{
                          final dir = await getTemporaryDirectory();
                          String path = dir.path;
                          String fileName = await _screenshotImg();
                          ImageGallerySaverPlus.saveFile(fileName).then((value) {
                            showToast('保存成功~');
                            SmartDialog.dismiss();
                          });
                          // await _screenshotController.captureAndSave(
                          //     path, //set path where screenshot will be saved
                          //     fileName: fileName,
                          //     pixelRatio: window.devicePixelRatio ?? 2)
                          //     .then((value) {
                          //   ImageGallerySaver.saveFile('$path/$fileName').then((value) {
                          //     showToast('保存成功~');
                          //     SmartDialog.dismiss();
                          //   });
                          // });
                        },
                        child: Container(
                          // width: 135.w,
                          // margin: EdgeInsets.only(right: 40.w),
                          child: Column(
                            children: [
                              Image.asset("assets/share/share_save.png",width: 90.w,),
                              SizedBox(height: 10.w,),
                              Text('保存图片',style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 28.sp
                              ),)
                            ],
                          ),
                        ),
                      ),visible: widget.shareType==2,),
                      Visibility(child: GestureDetector(
                        onTap: (){
                          if(widget.clickFun!=null){
                            widget.clickFun!(3);
                          }
                        },
                        child: Container(
                          // width: 135.w,
                          // margin: EdgeInsets.only(right: 40.w),
                          child: Column(
                            children: [
                              Container(
                                width: 95.w,
                                height: 95.w,
                                padding: EdgeInsets.all(15.w),
                                decoration: BoxDecoration(
                                    color: Colors.black12,
                                    borderRadius: BorderRadius.circular(100.w)
                                ),
                                child: Image.asset("assets/home/jubao.png",width: 50.w,fit: BoxFit.fitWidth,),
                              ),
                              SizedBox(height: 10.w,),
                              Text('举报',style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 28.sp
                              ),)
                            ],
                          ),
                        ),
                      ),visible: widget.contentType==1,),
                    ],
                  ),
                  padding:EdgeInsets.only(bottom: 30.w,left: 30.w,right: 30.w),
                ),
                // Visibility(child: Container(
                //   height: 0.4,
                //   margin: EdgeInsets.only(bottom: 20.w),
                //   color: Color(0xffE9E8E9),
                // ),visible: widget.isLocal,),
                // Visibility(child: Container(
                //   child: Row(
                //     children: [
                //       GestureDetector(
                //         onTap: (){
                //           if(widget.clickFun!=null){
                //             widget.clickFun(1);
                //           }
                //         },
                //         child: Container(
                //           margin: EdgeInsets.only(right: 40.w),
                //           child: Column(
                //             children: [
                //               Image.asset("assets/share/share_save.png",width: 90.w,),
                //               SizedBox(height: 10.w,),
                //               Text('保存本地',style: TextStyle(
                //                   color: Color(0xff999999),
                //                   fontSize: 28.sp
                //               ),)
                //             ],
                //           ),
                //         ),
                //       ),
                //       // GestureDetector(
                //       //   onTap: (){
                //       //
                //       //   },
                //       //   child: Container(
                //       //     margin: EdgeInsets.only(right: 40.w),
                //       //     child: Column(
                //       //       children: [
                //       //         Image.asset("assets/share/share_change_title.png",width: 90.w,),
                //       //         SizedBox(height: 10.w,),
                //       //         Text('修改标题',style: TextStyle(
                //       //             color: Color(0xff999999),
                //       //             fontSize: 28.sp
                //       //         ),)
                //       //       ],
                //       //     ),
                //       //   ),
                //       // ),
                //       // GestureDetector(
                //       //   onTap: (){
                //       //
                //       //   },
                //       //   child: Container(
                //       //     margin: EdgeInsets.only(right: 40.w),
                //       //     child: Column(
                //       //       children: [
                //       //         Image.asset("assets/share/share_delete.png",width: 90.w,),
                //       //         SizedBox(height: 10.w,),
                //       //         Text('删除',style: TextStyle(
                //       //             color: Color(0xff999999),
                //       //             fontSize: 28.sp
                //       //         ),)
                //       //       ],
                //       //     ),
                //       //   ),
                //       // ),
                //       GestureDetector(
                //         onTap: (){
                //           SmartDialog.dismiss();
                //           if(widget.clickFun!=null){
                //             widget.clickFun(2);
                //           }
                //         },
                //         child: Container(
                //           margin: EdgeInsets.only(right: 40.w),
                //           child: Column(
                //             children: [
                //               Image.asset("assets/share/share_new_img.png",width: 100.w,),
                //               SizedBox(height: 10.w,),
                //               Text('生成图片',style: TextStyle(
                //                   color: Color(0xff999999),
                //                   fontSize: 28.sp
                //               ),)
                //             ],
                //           ),
                //         ),
                //       )
                //     ],
                //   ),
                //   padding:EdgeInsets.only(bottom: 20.w,left: 30.w,right: 30.w,top: 30.w),
                // ),visible: widget.isLocal,),
                Container(
                  height: 20.w,
                  color: Color(0xffF4F4F4),
                ),
                GestureDetector(
                  onTap: (){
                    SmartDialog.dismiss();
                  },
                  child: Container(
                    height: 80.w,
                    color: Colors.white,
                    alignment: Alignment.center,
                    child: Text('取消',style: TextStyle(
                        color: Color(0xff232323),
                        fontSize: 32.sp
                    ),),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  Widget videoWidget(){
    if(widget.videoDataEntity==null){
      return Container();
    }
    print('0======='+widget.aspectRadio.toString());

    print('1======='+'${widget.videoDataEntity?.videoUrl}?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast');

    print('2======='+'${widget.videoDataEntity?.videoUrl}?x-oss-process=video/snapshot,t_1000,f_jpg,w_${(1.sw-60.w).toInt()},h_${(800.w).toInt()},m_fast');
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.w)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Container(
            width: 1.sw-60.w,
            height: widget.aspectRadio!<1? 800.w:(1.sw-60.w)/widget.aspectRadio!,
            child: Stack(
              children: [
                Center(
                  child: ClipRRect(
                    child: ASRCacheImage(
                      width: 1.sw-60.w,
                      height: widget.aspectRadio!<1? 800.w:(1.sw-60.w)/widget.aspectRadio!,
                      image: '${widget.videoDataEntity?.videoUrl}?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast',
                      fit: BoxFit.fill,
                    ),
                    borderRadius: BorderRadius.circular(10.w),
                  ),
                ),

                Center(
                  child: Image.asset('assets/home/home_play.png',width: 100.w,),
                )
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.only(right: 30.w,left: 30.w,top: 40.w),
            color: Colors.white,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Text('${widget.videoDataEntity?.userName}',style: TextStyle(
                        color: Colors.black,
                        fontSize: 34.sp,
                        fontWeight: FontWeight.w500
                    ),),
                    SizedBox(width: 20.w,),
                    Text('发布了视频',style: TextStyle(
                        color: Color(0xff888888),
                        fontSize: 28.sp,
                        fontWeight: FontWeight.w400
                    ),),
                  ],
                ),
                Visibility(child: Container(
                  margin: EdgeInsets.only(top: 20.w),
                  child: Text('${widget.videoDataEntity?.videoDesc}',style: TextStyle(
                      color: Color(0xff444444),
                      fontSize: 30.sp,
                      fontWeight: FontWeight.w400
                  ),),
                )),
                timeWidget()
              ],
            ),
          ),
          qrWidget(),
        ],
      ),
    );
  }
  Widget xianhuoWidget(){
    if(widget.xianHuoDataEntity==null){
      return Container();
    }
    String location;
    if(widget.xianHuoDataEntity?.address!=null&&widget.xianHuoDataEntity!.address!.isNotEmpty){
      List arr = widget.xianHuoDataEntity!.address!.split(' ');
      print('arr====='+arr.toString());
      if(arr.length>=4){
        location = '${arr[0]??''} ${arr[1]??''} ${arr[2]??''}';
      }else{
        location = widget.xianHuoDataEntity!.address!;
      }
    }

    return Container(
      decoration: BoxDecoration(
        color: widget.xianHuoDataEntity?.publishType==1?Colors.transparent:Colors.white,
        borderRadius: BorderRadius.circular(10.w)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Visibility(child: Container(
            width: 1.sw-60.w,
            height: 400.w,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10.w),
              color: Colors.white,
            ),
            child: Stack(
              children: [
                Container(
                  height: 400.w,
                  width: 1.sw-60.w,
                  color: Colors.transparent,
                ),
                Positioned(child: Visibility(child: ClipRRect(
                  child: ASRCacheImage(
                    width: 1.sw-60.w,
                    image: widget.xianHuoDataEntity!.images!=null&&widget.xianHuoDataEntity!.images!.isNotEmpty?widget.xianHuoDataEntity!.images![0]:'',
                    fit: BoxFit.fitWidth,
                  ),
                  borderRadius: BorderRadius.circular(10.w),
                ),visible:true,),bottom: 40.w,left: 0,right: 0,top: 0,),
                Positioned(
                  child: Container(
                    height: 80.w,
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(horizontal:30.w),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/home/share_xh_jg.png'),
                          fit: BoxFit.fill
                      ),
                      // gradient: LinearGradient(
                      //     colors: [Color(0xffEB6C2D),Color(0xffE87941)]
                      // ),
                      // borderRadius: BorderRadius.circular(10.w)
                    ),
                    child: RichText(
                      text: TextSpan(
                          text: '￥${widget.xianHuoDataEntity?.price}元',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 42.sp,
                              fontWeight: FontWeight.w600
                          ),
                          children: [
                            TextSpan(
                              text: '${StringTool.getDWstr(widget.xianHuoDataEntity!.productUnit!)}',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 28.sp,
                                  fontWeight: FontWeight.w600
                              ),
                            )
                          ]
                      ),
                      // Text('￥${widget.xianHuoDataEntity.price}元${StringTool.getDWstr(widget.xianHuoDataEntity.productUnit)}',style: TextStyle(
                      //     color: Colors.white,
                      //     fontSize: 40.sp,
                      //     fontWeight: FontWeight.w600
                      // ),)
                    ),
                  ),left: 0,bottom: 0,),
                Positioned(
                  child: Container(
                    child: Image.asset('assets/home/share_sm_icon.png',height: 140.w,),
                  ),right: 0,top: 0,)
              ],
            ),
          ),visible: widget.xianHuoDataEntity?.publishType==0,),
          Visibility(child:  Container(
            color: Colors.transparent,
            height: 140.w,
            child: Stack(
              children: [
                Positioned(
                  child: Container(
                    height: 100.w,
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 20.w),
                    decoration: BoxDecoration(
                      color: Colors.white
                    ),
                  ),left: 0,bottom: 0,right: 0,),
                Positioned(
                  child: Container(
                    height: 80.w,
                    alignment: Alignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 30.w),
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/home/share_xh_jg.png'),
                          fit: BoxFit.fill
                      ),
                      // gradient: LinearGradient(
                      //     colors: [Color(0xffEB6C2D),Color(0xffE87941)]
                      // ),
                      // borderRadius: BorderRadius.circular(10.w)
                    ),
                    child: RichText(
                      text: TextSpan(
                          text: '￥${widget.xianHuoDataEntity?.price}元',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 42.sp,
                              fontWeight: FontWeight.w600
                          ),
                          children: [
                            TextSpan(
                              text: '${StringTool.getDWstr(widget.xianHuoDataEntity!.productUnit!)}',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 28.sp,
                                  fontWeight: FontWeight.w600
                              ),
                            )
                          ]
                      ),
                      // Text('￥${widget.xianHuoDataEntity.price}元${StringTool.getDWstr(widget.xianHuoDataEntity.productUnit)}',style: TextStyle(
                      //     color: Colors.white,
                      //     fontSize: 40.sp,
                      //     fontWeight: FontWeight.w600
                      // ),)
                    ),
                  ),left: 0,top: 0,),
                Positioned(
                  child: Container(
                    child: Image.asset('assets/home/share_cg_icon.png',height: 140.w,),
                  ),right: 0,top: 30.w,)
              ],
            ),
          ),visible: widget.xianHuoDataEntity?.publishType==1),
          Container(
            color: Colors.white,
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.symmetric(horizontal: 30.w,vertical: 30.w),
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('${widget.xianHuoDataEntity?.name??''}',style: TextStyle(
                          color: Colors.black,
                          fontSize: 34.sp,
                          fontWeight: FontWeight.w500
                      ),),
                      SizedBox(height: 20.w,),
                      Visibility(child: Text('${widget.xianHuoDataEntity?.description??''}',style: TextStyle(
                          color: Color(0xff444444),
                          fontSize: 28.sp,
                          fontWeight: FontWeight.w400
                      ))),
                      // Visibility(
                      //   child: Container(
                      //     margin: EdgeInsets.only(top: 30.w),
                      //     child: Row(
                      //       mainAxisAlignment: MainAxisAlignment.start,
                      //       children: [
                      //         Container(
                      //           child: Image.asset('assets/fabu/fabu_dt.png',width: 30.w,),
                      //           margin: EdgeInsets.only(right: 20.w),
                      //         ),
                      //         Expanded(child: Text('${location??''}',style: TextStyle(
                      //             color: Color(0xff444444),
                      //             fontSize: 24.sp,
                      //             fontWeight: FontWeight.w400
                      //         ))),
                      //       ],
                      //     ),
                      //   ),
                      //   visible: location!=null&&location.isNotEmpty,
                      // ),
                      timeWidget(),
                      Container(
                        child: Row(
                          children: [
                            ClipRRect(
                              child:ASRCacheImage(image:widget.xianHuoDataEntity?.user?.img??'assets/icon/p_head.png',width: 110.w,height: 110.w,fit: BoxFit.fitWidth,),
                              borderRadius: BorderRadius.circular(100.w),
                            ),
                            Expanded(child: Container(
                              margin: EdgeInsets.symmetric(horizontal: 20.w,),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.spaceAround,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      RichText(
                                        maxLines: 1,
                                        softWrap: true,
                                        text: TextSpan(
                                          text: '${widget.xianHuoDataEntity?.user?.name}',
                                          style: TextStyle(
                                              fontSize: 30.sp,
                                              color: Colors.black,
                                              fontWeight: FontWeight.w600
                                          ),
                                        ),
                                        textAlign: TextAlign.left,
                                      ),
                                      SizedBox(width: 20.w,),
                                      Visibility(child: Image.asset('assets/min/min_sm.png',height: 30.w,),visible: widget.xianHuoDataEntity?.user?.card==1,),
                                      SizedBox(width: 20.w,),
                                      Visibility(child: Image.asset('assets/min/min_vip.png',height: 30.w,),visible: widget.xianHuoDataEntity?.user?.vip==1,),
                                    ],
                                  ),
                                  SizedBox(height: 10.w,),
                                  Visibility(child: Row(
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      Image.asset('assets/home/smrz_succ.png',height: 30.w,),
                                      SizedBox(width: 20.w,),
                                      Text('${widget.xianHuoDataEntity?.user?.realName??''}',style: TextStyle(
                                          fontSize: 24.sp,
                                          color: Color(0xff5A5A5A),
                                          fontWeight: FontWeight.w400
                                      ))
                                    ],
                                  ),visible: widget.xianHuoDataEntity?.user?.card==1,),
                                ],
                              ),
                            )),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                qrWidget()
              ],
            ),
          )
        ],
      ),
    );
  }



  Widget yqWidget(){
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(10.w)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Container(
            child: ClipRRect(
              child: Image.asset('assets/home/yq_fx_bg.png',fit: BoxFit.fitWidth,width: 1.sw-60.w,),
              // borderRadius: BorderRadius.circular(10.w),
            ),
          ),
          qrWidget()
        ],
      ),
    );
  }

  Widget zxWidget(){
    if(widget.zixunDataEntity==null){
      return Container();
    }
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
        borderRadius: BorderRadius.circular(10.w)
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ClipRRect(
            child: ASRCacheImage(
              width: 1.sw-60.w,
              fit: BoxFit.fitWidth,
              image: 'assets/home/zx_fx_lp_top.png',
            ),
            borderRadius: BorderRadius.circular(10.w),
          ),
          Container(
            margin: EdgeInsets.only(top: 30.w),
            padding: EdgeInsets.symmetric(horizontal: 60.w),
            child: Row(
              children: [
                Image.asset('assets/home/zx_hs_rl.png',width: 35.w,),
                SizedBox(width: 20.w,),
                Text('${widget.zixunDataEntity?.createTime}',style: TextStyle(
                    color: Color(0xff444444),
                    fontSize: 28.sp,
                    fontWeight: FontWeight.w500
                ),)
              ],
            ),
          ),
          Container(
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.symmetric(horizontal: 60.w,),
            margin: EdgeInsets.only(top: widget.zixunDataEntity?.title!=null?30.w:0,bottom: widget.zixunDataEntity?.title!=null?10.w:0),
            child: Text(widget.zixunDataEntity?.title??'',style: TextStyle(
                color: widget.zixunDataEntity?.flag == 1? Color(0xffd7431f) : Colors.black,
                fontSize: 36.sp,
                fontWeight: FontWeight.w500
            ),),
          ),
          Container(
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.symmetric(horizontal: 60.w,),
            margin: EdgeInsets.only(bottom: (widget.zixunDataEntity?.content ==null || widget.zixunDataEntity?.content!.length ==0) ?0: 40.w),
            child: Container(
              child: Text(widget.zixunDataEntity?.content??'',style: TextStyle(
                  color: widget.zixunDataEntity?.flag == 1? Color(0xffd7431f) :Color(0xff444444),
                  fontSize: 32.sp,
                  height:(widget.zixunDataEntity?.content ==null || widget.zixunDataEntity?.content!.length ==0) ?0: 1.5
              ),),
            ),
          ),
          Visibility(child: Container(
            alignment: Alignment.center,
            padding: EdgeInsets.symmetric(horizontal: 60.w,),
            margin: EdgeInsets.only(bottom: 40.w),
            child: ASRCacheImage(
              image: widget.zixunDataEntity!.images!,
              width: double.infinity,
              fit: BoxFit.fitWidth,
            ),
          ),visible: widget.zixunDataEntity?.images!=null&&widget.zixunDataEntity!.images!.length>0,),
          Container(child: qrWidget(),padding: EdgeInsets.symmetric(horizontal: 30.w),)
        ],
      ),
    );
  }

  Widget qrWidget(){
    return Container(
      padding: EdgeInsets.only(left: 30.w,right: 30.w,bottom: 40.w),
      // height: 150.w,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10.w),bottomRight: Radius.circular(10.w))
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Text('下载粮策APP',style: TextStyle(
                  color: Color(0xffE45D11),
                  fontSize: 40.sp,
                  fontFamily: 'Schyler',
                  fontWeight: FontWeight.w500
              ),),
              SizedBox(height: 20.w,),
              Text('买卖存粮有策略，粮食行业都在用',style: TextStyle(
                  color: Color(0xff444444),
                  fontSize: 20.sp,
                  fontWeight: FontWeight.w500
              ),)
            ],
          ),
          Container(
            width: 0.5,
            height: 120.w,
            margin: EdgeInsets.only(left: 30.w,right: 45.w),
            color: Color(0xffE9E8E9),
          ),
          // QrImage(
          //   size: 140.w,
          //   padding: EdgeInsets.zero,
          //   data: webUrl,
          // ),
        ],
      ),
    );
  }
  Widget timeWidget(){
    var now = new DateTime.now();
    return Container(
      margin: EdgeInsets.symmetric(vertical: 40.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Expanded(child: Container(
            height: 0.2,
            // width: 100.w,
            color: Color(0xff989898),
          )),
          SizedBox(width: 30.w,),
          Text('${now.year}-${DateUtil.unitFormat(now.month)}-${DateUtil.unitFormat(now.day)} ${DateUtil.unitFormat(now.hour)}:${DateUtil.unitFormat(now.minute)}:${DateUtil.unitFormat(now.second)}',style: TextStyle(
              color: Color(0xff989898),
              fontSize: 28.sp,
              fontWeight: FontWeight.w400
          )),
          SizedBox(width: 30.w,),
          Expanded(child: Container(
            height: 0.2,
            // width: 100.w,
            color: Color(0xff989898),
          )),
        ],
      ),
    );
  }

  ///截图
  Future<String> _screenshotImg() async {
    String savePath = '';
    try {
      RenderRepaintBoundary boundary = _rootWidgetKey.currentContext?.findRenderObject()! as RenderRepaintBoundary;
      var _dpr = window.devicePixelRatio ?? 2;
      var image = await boundary.toImage(pixelRatio: _dpr);
      final dir = await getTemporaryDirectory();
      String path = dir.path;
      String fileName =
          DateTime.now().microsecondsSinceEpoch.toString() + '.png';
      File file = File('$path/$fileName');
      ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
      Uint8List? pngBytes = byteData?.buffer.asUint8List();
      if (!file.existsSync()) {
        file.createSync();
      }
      file.writeAsBytesSync(pngBytes!);
      savePath = file.path;
    } catch (e) {
      print(e);
    }
    return savePath;
  }

}
